﻿// -----------------------------------------------------------------------
// <copyright company="Christoph van der Fecht - VDsoft">
// This code can be used in commercial, free and open source projects.
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Newtonsoft.Json;

namespace VDsoft.SeriesNewsReader
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
			Properties.Settings.Default.SettingsSaving += this.OnSavingSettings;
			this.LoadMonitoredSeries();
		}

		private void OnSavingSettings(object sender, System.ComponentModel.CancelEventArgs e)
		{
			this.LoadMonitoredSeries();
		}

		private void LoadMonitoredSeries()
		{
			List<string> series = JsonConvert.DeserializeObject<List<string>>(Properties.Settings.Default.Series);

			if (series == null || series.Count == 0)
			{
				return;
			}

			List<FrameworkElement> filters = new List<FrameworkElement>()
			{
				new MenuItem() { Header = "All Series" }, 
				new MenuItem() { Header = "All My Series" }, 
				new Separator()
			};

			foreach (string name in series)
			{
				filters.Add(new MenuItem() { Header = name });
			}

			this.menuItemFilters.ItemsSource = filters;
		}

		private void OnHyperlinkClick(object sender, RoutedEventArgs e)
		{
			Hyperlink link = e.Source as Hyperlink;
			Process.Start(link.NavigateUri.ToString());
		}
	}
}
